export default function (ref) {
    return {
        mounted() {
            this.$refs[ref].addEventListener("scroll", this.handleMainScroll);
            this.$eventBus.$on("setMainScroll", this.handleSetMainScroll);
        },
        beforeDestroy() {
            this.$eventBus.$emit("mainScroll");
            this.$eventBus.$off("setMainScroll", this.handleSetMainScroll);
            this.$refs[ref].removeEventListener("scroll", this.handleMainScroll);
        },
        methods: {
            handleMainScroll() {
                this.$eventBus.$emit("mainScroll", this.$refs[ref])
            },
            handleSetMainScroll(newTop) {
                this.$refs[ref].scrollTop = newTop;
            }
        }
    }
}